<script src="/js/commentsRev.js"></script>
<script src="/js/errorReport.js"></script>
<?php Yii::app()->getClientScript()->registerScriptFile(Yii::app()->baseUrl.'/js/scrollTo.js'); ?>
<?php
    function printSubComments($target, $comments, $level, $canModerRevCom, $countMessagesData, $partner) {
        $level++;
        
        for($i=0; $i<count($comments); $i++) {
            if($target['comId'] == $comments[$i]['parentId']) {
                if($level < 7) {
                    if($comments[$i]['isDelegate']) 
                        echo '<ul class="comments is_off_ans">';
                    else echo '<ul class="comments">';
                } 
                echo '<a style="padding-top:65px;" id="com'.$comments[$i]['comId'].'"></a>';
                echo '<li id="comment'.$comments[$i]['comId'].'">'; 
                echo '<div class="comment_head">';           
                echo '<a id="com'.$comments[$i]['comId'].'"';
                if(!Yii::app()->user->isGuest){ echo 'class="comment_otv"';} 
                echo 'href="#com'.$comments[$i]['comId'].'">#</a>&nbsp;&nbsp;';
                
                echo Yii::app()->dateFormatter->format("dd MMMM yyyy года в HH:mm", $comments[$i]['date']).'&nbsp;&nbsp;&nbsp;';
                   $login = !empty($comments[$i]['displayName']) ? $comments[$i]['displayName'] : $comments[$i]['login'];
                echo '<a href="'.Yii::app()->createUrl('user/profile/profile', array('login'=>$comments[$i]['login'])).'">'.$login.'</a>&nbsp;';  
                
                foreach ($countMessagesData as $c) {
                     if($c['userId'] == $comments[$i]['comUid']) 
                         $number = $c['reviews'] + $c['newsComments'] + $c['forumComments'] + $c['revComments'] + $c['blogComments'];
                 }
                
                echo '<span class="comment_numb">'.$number.'</span>';
                
                if($partner['delegate1'] == $comments[$i]['comUid'] || $comments[$i]['comUid'] == $partner['delegate2']) {
                    echo ' <span class="sapport">САППОРТ</span>';
                }    
                
                echo '  </div> ';   
                
                echo '<div class="comment_body"><p>';
                echo $comments[$i]['text'];
               
                echo'</p> ';
               
                if(!Yii::app()->user->isGuest) :
                  echo '<a href="#comment-form" class="comment_otv">Ответить</a> ';
                endif;
                echo CHtml::hiddenField('', $comments[$i]['comId'], array('class'=>'comId'));
               
                if($canModerRevCom) {
                    echo ' | <a style="font-size:12px;" href="'.Yii::app()->createUrl('partner/profile/editRevCom', array('id'=>$comments[$i]['comId'])).'">Изменить</a>';
                }
                echo'</div>';
                printSubComments($comments[$i], $comments, $level, $canModerRevCom, $countMessagesData, $partner);
                echo '</li>';
                if($level < 7) echo '</ul>';
            }
        }
    }
?>
<?php $this->renderPartial('//partials/partnerMenu', array('partner'=>$partner, 'advertCode'=>$advertCode, 'cat'=>$cat, 'errorModel'=>$errorModel, 'userIsWork'=>$userIsWork, 'relProfiles'=>$relProfiles, 'subCats'=>$subCats, 'curent'=>'review','show_tabs'=>0));?> 
<?php 
        $isDelegateUnswered = false;
        if(!empty($comments)) {
            for($i=0;$i<count($comments); $i++) {
                if($comments[$i]['isDelegate']) {
                    $isDelegateUnswered = $comments[$i];
                    break;
                }    
            }
        } ?>


<div class="padding040">


    <div class="review_wrap" >
                <div class="rew_padd">
                      <div class="review_user_info pull-left">
                       
                          <div class="partner_review_user">
                          <div class="user_ava" style="margin-right: 10px;"> 
                             <?php if($rev['isAnonym']) : ?>
                                  <img src="/images/prettyImg/default-avatarl.jpg" style="width:30px; height:30px;" alt="" />
                              <?php elseif($rev['avatar']) : ?>
                                  <img src="/images/uploads/userAvatars/<?php echo $rev['avatar']; ?>" style="width:30px; height:30px;" alt="" />
                              <?php else : ?>
                                  <img src="/images/prettyImg/default-avatarl.jpg" style="width:30px; height:30px;" alt="" />
                              <?php endif; ?> 
                            </div>    
                               <?php if($rev['isAnonym']) : ?>
                                    <?php if($this->seeAnonymRev) : ?>
                                        Аноним(<a  href="<?php echo Yii::app()->createUrl('user/profile/profile', array('login'=>$rev['login'])); ; ?>"> <?php echo $rev['login']; ?> </a> )
                                    <?php else : ?>
                                        Аноним
                                    <?php endif; ?>
                                <?php else : ?>
                                    <a   href="<?php echo Yii::app()->createUrl('user/profile/profile', array('login'=>$rev['login'])); ; ?>"> <?php echo !empty($rev['displayName']) ? $rev['displayName'] : $rev['login']; ?> </a>
                                <?php endif; ?>
                            <span class="par_prof_lat_login"><?php echo Yii::app()->dateFormatter->format("dd MMMM yyyy", $rev['date']); ?></span>
                        </div>
                          
                         <div class="rew_rating">                            
                            <?php foreach ($revRatings as $rating) : ?>
                                <?php if($rating['type'] > 4) continue; ?>
                              <?php $name = "reviewRating".$rating['type'].""; ?>
                                <span class="par_prof_lat_login"><?php echo $rev[$name];?></span>
                                <?php $this->widget('CStarRating',array('name'=>$rating['id'], 'readOnly'=>true, 'value'=>$rating['val'], 'starCount'=>10, 'resetText'=>'Сбросить оценку'));?><br/>
                            <?php endforeach; ?>
                         </div>
                      </div>
                      <div class="review_user_info_cut"></div>
                
                
                      <div class="review_user_body">
                          <a class="review_user_head" href="">
                              <?php echo empty($rev['title']) ? '...' : $rev['title']; ?>
                          </a>                          
                          <div style="font-size:13px;margin-bottom: 15px;" >    <?php echo $rev['text']; ?></div>
                           <div>
                              <?php if(!empty($revImg)) : ?>
                                <?php foreach($revImg as $ratingImg) : ?>
                                    <?php if($ratingImg['onlyModerator'] && !Yii::app()->user->checkAccess('redactor')) continue; ?>
                                    <a style="text-decoration:none;" href="#modal<?php echo $ratingImg['imgId']; ?>" class="big-link" data-toggle="modal" >
                                        <img src="<?php echo Yii::app()->baseUrl.'/images/uploads/reviews/'.$ratingImg['smallImg']; ?>" style="width:40px;height:40px;" alt=""/>
                                    </a> 
                                    <div id="modal<?php echo $ratingImg['imgId']; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                            <h3 id="myModalLabel">Фото</h3>
                                        </div>
                                        <div class="modal-body">
                                            <img src="<?php echo Yii::app()->baseUrl.'/images/uploads/reviews/'.$ratingImg['bigImg']; ?>"/>
                                        </div>
                                    </div>
                                <?php endforeach; ?>
                              <?php endif; ?>         
                          </div>
                          <?php if($this->canModerRev) : ?>
                        <a href="<?php echo Yii::app()->createUrl('partner/profile/preview', array('url'=>$rev['url'])); ?>">Редактировать отзыв</a>
                    <?php endif; ?>
                       </div>
                     
                      
                   
                        
                    <?php if(Yii::app()->user->checkAccess('redactor') && !empty($rev['redactorNotice'])) : ?>
                        <div style="background-color: greenyellow">
                            <?php echo $rev['redactorNotice']; ?>
                        </div>    
                    <?php endif; ?>
                  <div class="clearfix"></div>
              </div>
                 <?php if(!empty($rev['delegUns'])) : ?>
                     <?php echo CHtml::hiddenField('', '0', array('class'=>'comId')); ?>
                     <?php if(!Yii::app()->user->isGuest) : ?>
                     <span style="cursor:pointer; color: brown;" class="comment">Комментировать</span>
                    <?php endif; ?>
                    <?php if($this->canModerRev) : ?>
                        <a href="<?php echo Yii::app()->createUrl('partner/profile/preview', array('url'=>$rev['url'])); ?>">Изменить</a>
                    <?php endif; ?>
                    <div class="form" style="display:none; height: 350px"></div>

                           <div class="otvet_pred_wrap">
                               <div class="pull-left" style="width:240px;">
                                        Комментарий представителя партнерской программы<br/>
                                        <a href="<?php echo Yii::app()->createUrl('user/profile/profile', array('login'=>$item['delegUns']['login'])); ?>"><?php echo !empty($item['delegUns']['displayName']) ? $item['delegUns']['displayName'] : $item['delegUns']['login']; ?></a>&nbsp;

                               </div>         

                              <div class="pull-left" style="width:540px;margin-left: 20px;"><?php echo $item['delegUns']['text']; ?></div>
                              <div class="clearfix"></div>
                            </div>
                    <?php endif; ?>
             </div>     








</div>


<div class="padding040">

<h2 class="com_head">Комментарии</h2>
</div>

<?php if(!empty($comments)) : ?>
    <?php for($i = 0; $i<count($comments); $i++) : ?>
        <?php // if($comments[$i]['isDelegate']) continue; ?>
            <?php if(!$comments[$i]['parentId']) : ?>
            <ul class="comments <?php  if($comments[$i]['isDelegate']) { ?> is_off_ans <?php } ?>">
                <a style="padding-top:65px;" id="com<?php echo $comments[$i]['comId']; ?>"></a>
                <li id="comment<?php echo $comments[$i]['comId'];  ?>">
                <div class="comment_head"><a href="#com<?php echo $comments[$i]['comId'];  ?>">#</a>&nbsp;&nbsp;<?php echo Yii::app()->dateFormatter->format("dd MMMM yyyy года в HH:mm", $comments[$i]['date']); ?>&nbsp;&nbsp;&nbsp;
                    <?php if($comments[$i]['isAnonym']) : ?>
                        <?php if($this->seeAnonymRev) : ?>
                            Аноним (<a href="<?php echo Yii::app()->createUrl('user/profile/profile', array('login'=>$comments[$i]['login'])); ?>"><?php echo $comments[$i]['login']; ?></a>)&nbsp;
                        <?php else : ?>
                            Аноним <?php echo !Yii::app()->user->isGuest && $comments[$i]['userId'] == Yii::app()->user->getId() ? '(Я)' : ''; ?>
                        <?php endif; ?>   
                            
                    <?php else : ?>
                     <a href="<?php echo Yii::app()->createUrl('user/profile/profile', array('login'=>$comments[$i]['login'])); ?>"><?php echo !empty($comments[$i]['displayName']) ? $comments[$i]['displayName'] : $comments[$i]['login']; ?></a>&nbsp;
                    <?php endif; ?>    
                     <?php 
                     foreach ($countMessagesData as $c) {
                         if($c['userId'] == $comments[$i]['comUid']) 
                             $number = $c['reviews'] + $c['newsComments'] + $c['forumComments'] + $c['revComments'] + $c['blogComments'];
                     } ?>
                   <span class="comment_numb"><?php echo $number; ?></span>  
                   <?php if($partner['delegate1'] == $comments[$i]['comUid'] || $comments[$i]['comUid'] == $partner['delegate2']) {
                             echo ' <span class="sapport">САППОРТ</span>';
                        } ?>
                   
                    </div>    
                        
                    <div class="comment_body"><p><?php echo $comments[$i]['text']; ?></p>
                          <?php if(!Yii::app()->user->isGuest) : ?>
                        <a href="#comment-form" class="comment_otv">Ответить</a>
                    <?php endif; ?>
                         <?php echo CHtml::hiddenField('', $comments[$i]['comId'], array('class'=>'comId')); ?>
                    <?php if($this->canModerRevCom) : ?>    
                        <?php echo ' | <a style="font-size:12px;" href="'.Yii::app()->createUrl('partner/profile/editRevCom', array('id'=>$comments[$i]['comId'])).'">Изменить</a>'; ?>
                    <?php endif; ?>
                        
                      
                        
                        
                  
                    </div>
                   
                   
                    
                    <?php printSubComments($comments[$i], $comments, 1, $this->canModerRevCom, $countMessagesData, $partner); ?>
                </li>
                </ul> 
            <?php endif; ?>
    <?php endfor; ?>
<?php endif; ?>


  <?php // printSubComments($comments[$i], $comments, 1, $this->canModerRevCom); ?>

<div class="padding4020">
       <?php if(!Yii::app()->user->isGuest) : ?>
                        <a href="#comment-form" style="margin-bottom:20px;" class="comment_otv">Комментировать</a>
                    <?php endif; ?>
    
    
    
                        <div  id="comment-form" class="hiddenForm hide">   
<div class="comment_form_cut"></div>
<div  class=" comment_form">
    <?php echo CHtml::beginForm(); ?>
<div style="width:100%;display: inline-block;"><span class="pull-right close_form"></span></div>
<div class="pull-left">
    <div class="user_av_form_rew pull-left">
                <?php if (Yii::app()->user->getState('avatar')) : ?>
                    <img alt="" src="/images/uploads/userAvatars/<?php echo Yii::app()->user->getState('avatar'); ?>" style="height:28px; width:28px;" alt="" />
                <?php else : ?>
                    <img src="/images/prettyImg/default-avatarl.jpg"  style="height:28px; width:28px;" alt="" />
                <?php endif; ?> 
     </div>   
    <?php echo CHtml::activeTextArea($model, 'text', array('class'=>'text_area_comm', 'id'=>'editor')); ?>

</div>

<div class="pull-left" style="margin-left: 33px;margin-top: 33px;">
    <?php if(!Yii::app()->user->isGuest && $partner['delegate1'] != Yii::app()->user->getId() && $partner['delegate2'] != Yii::app()->user->getId()) : ?>
        <?php echo CHtml::activeCheckBox($model, 'isAnonym',array('id'=>'is_an_comment')); ?><label for="is_an_comment"><span style="font-size: 12px;">Отправить анонимно</label>
    <?php endif; ?>    
    <?php if(!Yii::app()->user->isGuest && !$isDelegateUnswered && ($partner['delegate1'] == Yii::app()->user->getId() || $partner['delegate2'] == Yii::app()->user->getId())) : ?>
        <?php echo CHtml::activeCheckBox($model, 'isDelegate',array('id'=>'is_off_comment')); ?><label for="is_off_comment"><span style="font-size: 12px;line-height: 12px;">Отправить как официальный<br/> ответ представителя<br/> партнерки.</label>
        <br/>
        <div class="ct_znak"></div>
        <div style="color:#898989;font-size:12px;margin-left: 20px;">Сообщение буддет помечено<br/> вот таким четким значком.</div>
    <?php endif; ?>
        
</div>          
        
  <div class="clearfix"></div> 
  
  <div style="height:40px;"></div>
   
    
  <div class="pull-left">
    <?php echo CHtml::submitButton('Добавить комментарий',array('class'=>'bt_submit_review')); ?> 
   </div>
   <div class="pull-right"  style="margin-top:10px;">
    <div  class="subscrible_form_com pull-left " style="display: block;"> 
        <input placeholder="Подписаться на комментарии" id="subscrEmail" class="subscrible_input_com" type="text" value="" name="">    <div class="subscrible_sub" id="submitSubscrWindow"> </div>
    </div>
   </div>
   <div class="clearfix"></div> 
    <?php echo CHtml::activeHiddenField($model, 'parentId', array('value'=>'', 'class'=>'comParentId')); ?>
    <?php echo CHtml::activeHiddenField($model, 'revId', array('value'=>$rev['revId'])); ?>
    <?php echo CHtml::endForm(); ?>
      
        
</div>
</div>


</div>




